package com.jxt.myjxtmanager.views.popwindow;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.jxt.myjxtmanager.R;

import java.util.List;


/**
 * Created by qm on 2016/12/16 0016.
 */
public class PopRecyOneToSixAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {

    private List<PopRecyOneToSixInfo> list_data;
    private LayoutInflater inflater;
    private Context context;
    private int selectItem_One = -1;//标记item选中状态
    private int selectItem_Two = -1;//标记item选中状态

    public PopRecyOneToSixAdapter(List<PopRecyOneToSixInfo> list_data, Context context) {
        this.list_data = list_data;
        this.inflater = LayoutInflater.from(context);
        this.context = context;
    }

    public int getSelectItem_One() {
        return selectItem_One;
    }

    public void setSelectItem_One(int selectItem_One) {
        this.selectItem_One = selectItem_One;
    }

    public int getSelectItem_Two() {
        return selectItem_Two;
    }

    public void setSelectItem_Two(int selectItem_Two) {
        this.selectItem_Two = selectItem_Two;
    }

    /**
     * 定义点击每项的接口,此处只实现了点击，没有实现长按
     */
    public interface OnItemClickLitener {
        void OnItemClick(View view, int positon, int type);

        void OnItemLongClick(View view, int position);
    }

    private OnItemClickLitener mOnItemClickLitener;

    public void setOnItemClickLitener(OnItemClickLitener mOnItemClickLitener) {
        this.mOnItemClickLitener = mOnItemClickLitener;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {


        View view;
        RecyclerView.ViewHolder mViewHolder;
        if (viewType == 1) {

            view = inflater.inflate(R.layout.item_pop_choose_title, parent, false);
            mViewHolder = new tViewHolder(view);
        } else {
            view = inflater.inflate(R.layout.item_pop_choose_log, parent, false);
            mViewHolder = new gViewHolder(view);
        }

        return mViewHolder;
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, final int position) {

        switch (getItemViewType(position)) {
            case 1:
                final tViewHolder gHolder = (tViewHolder) holder;
                gHolder.txt_pTitle.setText(list_data.get(position).getTitle());
//                gHolder.txt_pGName.setTextColor(0xff8E8E93);
//                gHolder.txt_pGName.setBackgroundResource(R.drawable.bg_circle_pop);
                if (mOnItemClickLitener != null) {
                    gHolder.txt_pTitle.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View view) {
                            //Toast.makeText(context,list_data.get(position).getName(),Toast.LENGTH_SHORT).show();
                            mOnItemClickLitener.OnItemClick(gHolder.itemView, position, 1);
                        }
                    });
                }
                break;
            case 3:
                final gViewHolder tHolder = (gViewHolder) holder;
                tHolder.txt_pGName.setText(list_data.get(position).getThreeName());
//                tHolder.txt_pTitle.setBackgroundResource(android.R.color.transparent);
                if (getSelectItem_One() >= 0 && getSelectItem_One() == position) {//bg_circle_pop_btn
                    tHolder.txt_pGName.setBackgroundResource(R.drawable.bg_circle_pop_btn_press);
                    tHolder.txt_pGName.setTextColor(0xff40c5f1);
                } else {
                    tHolder.txt_pGName.setBackgroundResource(R.drawable.bg_circle_pop_btn_gray);
                    tHolder.txt_pGName.setTextColor(0xff8E8E93);
                }
                if (mOnItemClickLitener != null) {
                    tHolder.txt_pGName.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View view) {
                            //Toast.makeText(context,list_data.get(position).getName(),Toast.LENGTH_SHORT).show();
                            mOnItemClickLitener.OnItemClick(tHolder.itemView, position, 3);
                        }
                    });
                }
                break;
            case 6:
                final gViewHolder tHolder2 = (gViewHolder) holder;
                tHolder2.txt_pGName.setText(list_data.get(position).getSixName());
//                tHolder.txt_pTitle.setBackgroundResource(android.R.color.transparent);
                if (getSelectItem_Two() >= 0 && getSelectItem_Two() == position) {//bg_circle_pop_btn
                    tHolder2.txt_pGName.setBackgroundResource(R.drawable.bg_circle_pop_btn_press);
                    tHolder2.txt_pGName.setTextColor(0xff40c5f1);
                } else {
                    tHolder2.txt_pGName.setBackgroundResource(R.drawable.bg_circle_pop_btn_gray);
                    tHolder2.txt_pGName.setTextColor(0xff8E8E93);
                }
                if (mOnItemClickLitener != null) {
                    tHolder2.txt_pGName.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View view) {
                            //Toast.makeText(context,list_data.get(position).getName(),Toast.LENGTH_SHORT).show();
                            mOnItemClickLitener.OnItemClick(tHolder2.itemView, position, 6);
                        }
                    });
                }
                break;

        }

    }

    private void setitembg(int position) {

    }

    @Override
    public int getItemViewType(int position) {

        return list_data.get(position).getType();
    }

    @Override
    public int getItemCount() {
        return list_data.size();
    }


    /**
     * 类别形式的布局数据
     */
    class tViewHolder extends RecyclerView.ViewHolder {

        TextView txt_pTitle;

        public tViewHolder(View itemView) {
            super(itemView);
            txt_pTitle = (TextView) itemView.findViewById(R.id.tv_pop);
        }
    }

    /**
     * Grid形式的布局数据
     */
    class gViewHolder extends RecyclerView.ViewHolder {

        TextView txt_pGName;

        public gViewHolder(View itemView) {
            super(itemView);

            txt_pGName = (TextView) itemView.findViewById(R.id.tv_pop);
        }
    }


}
